home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / full / jbuild / setup / JBuilder / jhelp.z / AppletButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-11  |  4.0 KB  |  143 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.Frame;
  8. import java.awt.GridLayout;
  9. import java.awt.Label;
  10. import java.awt.Window;
  11.  
  12. public class AppletButton extends Applet implements Runnable {
  13.    int frameNumber = 1;
  14.    String windowClass;
  15.    String buttonText;
  16.    String windowTitle;
  17.    int requestedWidth;
  18.    int requestedHeight;
  19.    Button button;
  20.    Thread windowThread;
  21.    Label label;
  22.    boolean pleaseCreate = false;
  23.  
  24.    public void init() {
  25.       this.windowClass = ((Applet)this).getParameter("WINDOWCLASS");
  26.       if (this.windowClass == null) {
  27.          this.windowClass = "TestWindow";
  28.       }
  29.  
  30.       this.buttonText = ((Applet)this).getParameter("BUTTONTEXT");
  31.       if (this.buttonText == null) {
  32.          this.buttonText = "Click here to bring up a " + this.windowClass;
  33.       }
  34.  
  35.       this.windowTitle = ((Applet)this).getParameter("WINDOWTITLE");
  36.       if (this.windowTitle == null) {
  37.          this.windowTitle = this.windowClass;
  38.       }
  39.  
  40.       String var1 = ((Applet)this).getParameter("WINDOWWIDTH");
  41.       if (var1 != null) {
  42.          try {
  43.             this.requestedWidth = Integer.parseInt(var1);
  44.          } catch (NumberFormatException var4) {
  45.          }
  46.       }
  47.  
  48.       String var2 = ((Applet)this).getParameter("WINDOWHEIGHT");
  49.       if (var2 != null) {
  50.          try {
  51.             this.requestedHeight = Integer.parseInt(var2);
  52.          } catch (NumberFormatException var3) {
  53.          }
  54.       }
  55.  
  56.       ((Container)this).setLayout(new GridLayout(2, 0));
  57.       ((Container)this).add(this.button = new Button(this.buttonText));
  58.       this.button.setFont(new Font("Helvetica", 0, 14));
  59.       ((Container)this).add(this.label = new Label("", 1));
  60.    }
  61.  
  62.    public void start() {
  63.       if (this.windowThread == null) {
  64.          this.windowThread = new Thread(this, "Bringing Up " + this.windowClass);
  65.          this.windowThread.start();
  66.       }
  67.  
  68.    }
  69.  
  70.    public synchronized void run() {
  71.       Object var1 = null;
  72.       Object var2 = null;
  73.       Object var3 = null;
  74.  
  75.       try {
  76.          var8 = Class.forName(this.windowClass);
  77.       } catch (Exception var7) {
  78.          this.label.setText("Can't create window: Couldn't find class " + this.windowClass);
  79.          this.button.disable();
  80.          return;
  81.       }
  82.  
  83.       Class var9 = var8;
  84.  
  85.       for(var10 = var8.getName(); !var10.equals("java.lang.Object") && !var10.equals("java.awt.Frame"); var10 = var9.getName()) {
  86.          var9 = var9.getSuperclass();
  87.       }
  88.  
  89.       if (var10 != null && !var10.equals("java.lang.Object")) {
  90.          if (var10.equals("java.awt.Frame")) {
  91.             while(this.windowThread != null) {
  92.                while(!this.pleaseCreate) {
  93.                   try {
  94.                      this.wait();
  95.                   } catch (InterruptedException var6) {
  96.                   }
  97.                }
  98.  
  99.                this.pleaseCreate = false;
  100.                Object var4 = null;
  101.  
  102.                try {
  103.                   var11 = (Frame)var8.newInstance();
  104.                } catch (Exception var5) {
  105.                   this.label.setText("Couldn't create instance of class " + this.windowClass);
  106.                   this.button.disable();
  107.                   return;
  108.                }
  109.  
  110.                if (this.frameNumber == 1) {
  111.                   var11.setTitle(this.windowTitle);
  112.                } else {
  113.                   var11.setTitle(this.windowTitle + ": " + this.frameNumber);
  114.                }
  115.  
  116.                ++this.frameNumber;
  117.                ((Window)var11).pack();
  118.                if (this.requestedWidth > 0 | this.requestedHeight > 0) {
  119.                   ((Component)var11).resize(Math.max(this.requestedWidth, ((Component)var11).size().width), Math.max(this.requestedHeight, ((Component)var11).size().height));
  120.                }
  121.  
  122.                ((Window)var11).show();
  123.                this.label.setText("");
  124.             }
  125.          }
  126.  
  127.       } else {
  128.          this.label.setText("Can't create window: " + this.windowClass + " isn't a Frame subclass.");
  129.          this.button.disable();
  130.       }
  131.    }
  132.  
  133.    public synchronized boolean action(Event var1, Object var2) {
  134.       if (var1.target instanceof Button) {
  135.          this.label.setText("Please wait while the window comes up...");
  136.          this.pleaseCreate = true;
  137.          this.notify();
  138.       }
  139.  
  140.       return true;
  141.    }
  142. }
  143.